package com.lizx.persional.common.utils;

import com.baomidou.mybatisplus.plugins.Page;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author 江苏博沣
 * @Description
 * @Date Create in 2018/3/9 13:51
 */
@Data
@NoArgsConstructor
public class ResultPage  implements Serializable {
    private static final long serialVersionUID = -2768413316655692989L;

    private static final Logger LOGGER = LoggerFactory.getLogger(Result.class);

    private static final int SUCCESS = 1;
    private static final int FAIL = 0;
    private static Map<Integer, String> errorCodesMap = new HashMap<Integer, String>() {
        private static final long serialVersionUID = 5926543871947636499L;

        {
            put(FAIL, "系统繁忙");
            put(SUCCESS, "请求成功");
        }
    };
    protected Object data;
    protected Integer total;
    private Integer errcode = SUCCESS;
    private String errmsg = "ok";
    private String msgid;

    public ResultPage(Object data, Integer total, Integer errcode, String errmsg, String msgid) {
        this.data = data;
        this.total = total;
        this.errcode = errcode;
        this.errmsg = errmsg;
        this.msgid = msgid;
    }

    public static ResultPage success(Page page){
        return new ResultPage(page.getRecords(),page.getTotal(),SUCCESS,"ok",null);
    }

    public static ResultPage fail(){
        return new ResultPage(null,null,FAIL,"服务器内部错误",null);
    }
}
